<style lang="less">
    @import '../../styles/common.less';
    @import '../tables/components/table.less';
</style>
<template>
    <div>
        <Form  :label-width="80" style="height: 38px;margin: 5px 0">
            <Input v-model="pic"   placeholder="最小价格"  style="width: 200px;margin-right: 3px;"></Input>
            <Input v-model="nums"  placeholder="最小数量"  style="width: 200px"></Input>
            <DatePicker v-model="time" type="datetime" placeholder="请输入交易开始时间" style="width: 200px"></DatePicker>
            <DatePicker v-model="endtime" type="datetime" placeholder="请输入交易结束时间" style="width: 200px"></DatePicker>
            <FormItem label="状态" style="width: 300px;float: left" >
                <Select  v-model="name"  placeholder="请选择状态" style="margin-right: 3px;" >
                    <Option value="3">全部 </Option>
                    <Option value="0">失效 </Option>
                    <Option value="1">进行中</Option>
                    <Option value="2">已完成</Option>
                </Select>
            </FormItem>
            <span style="margin-left: 10px;line-height: 30px;">总额: {{sum}}</span>
            <div style="float: right">
            <Button type="info" style="float: right;margin-right: 5px" @click="load">查询</Button>
            </div>
        </Form>
        <Table :loading="loading" refs="table1"  :data="Message" :columns="columnsList"></Table>
        <Page :total="pageNum" :page-size="pageSize"  style="text-align: center;margin-top: 15px;" show-total @on-page-size-change='pageSizes'  show-elevator show-sizer @on-change="pageChange"></Page>

    </div>
</template>
<script>
    import $http from '../../utils/axiosWrap'
    import canEditTable from '../tables/components/canEditTable.vue'
    export default {
        data() {
            return {
                loading: true,
                Message:[],
                columnsList: [
                    {
                        title: '序号',
                        width: 80,
                        align: 'center',
                        render: (h, params) => {
                            return  params.index + (this.initPage- 1) * this.pageSize + 1
                        }
                    },
                    {
                        title: '买家名',
                        align: 'center',
                        key: 'buyerUsername',
                        editable: true
                    },
                    {
                        title: 'USDI价格',
                        align: 'center',
                        key: 'usdprice',
                        editable: true
                    },
                    {
                        title: '交易数量',
                        align: 'center',
                        key: 'coinAmount',
                        editable: true
                    },
                    {
                        title: '币种名称',
                        align: 'center',
                        key: 'coinName',
                        editable: true
                    },
                    {
                        title: '状态',
                        align: 'center',
                        render: (h, params) => {
                            if(params.row.status == 0){
                                return '失效'
                            }else if(params.row.status == 1){
                                return '进行中'
                            }else{
                                return '已完成'
                            }
                        }
                    },
                    {
                        title: '创建时间',
                        align: 'center',
                        width: 160,
                        key:'createDate'
                    }
                ],
                pageNum:0,
                initPage:1,
                name:'',
                coin:'',
                pic:'',
                nums:'',
                time:'',
                endtime:'',
                sum:0,
                pageSize:10
            }
        },
        created: function () {
            this.load()
        },
        methods: {
            pageChange(index){
                this.initPage = index
                this.loading = true
                this.load ()
            },
            setTime(time){
                var date = new Date(time);
                var month = date.getMonth() + 1
                var day =  date.getDate()
                var hours =   date.getHours()
                var minutes = date.getMinutes()
                var datese = date.getSeconds()
                if(datese /1  < 10){
                    datese = '0' +  datese
                }
                if(month /1  < 10){
                    month = '0' +  month
                }
                if(day /1  < 10){
                    day = '0' +  day
                }
                if(hours /1  < 10){
                    hours = '0' +  hours
                }
                if(minutes /1  < 10){
                    minutes = '0' +  minutes
                }
                return date.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + datese
            },
            load (){
                let _this = this
                let params = new URLSearchParams()
                params.append('page',_this.initPage)
                params.append('pageSize',_this.pageSize)
                params.append('price',_this.pic)
                params.append('number',_this.nums)
                if(_this.time){
                    params.append('time',_this.setTime(_this.time))
                }else{
                    params.append('time','')
                }
                if(_this.endtime){
                    params.append('endtime',_this.setTime(_this.endtime))
                }else{
                    params.append('endtime','')
                }
                params.append('business','0')
                if(_this.name != 3){
                    params.append('status',_this.name)
                }
               params.append('coinName','AITC')
                $http.post('/backgroundTradeTour/dealLogList',params).then(function (res) {
                 if(res.suc){
                    _this.Message = res.result.rows
                    _this.loading = false
                    _this.pageNum = res.result.total
                }else{
                    if(res.msg == "请先登录"){
                        _this.$Message.error('请重新登录！');
                    }else{
                        _this.$Message.error(res.msg);
                    }
                }
                })

                let paramss = new URLSearchParams()
                paramss.append('price',_this.pic)
                paramss.append('number',_this.nums)
                if(_this.time){
                    paramss.append('time',_this.setTime(_this.time))
                }else{
                    paramss.append('time','')
                }
                if(_this.endtime){
                    paramss.append('endtime',_this.setTime(_this.endtime))
                }else{
                    paramss.append('endtime','')
                }
                paramss.append('business','0')
                if(_this.name != 3){
                    paramss.append('status',_this.name)
                }
                paramss.append('coinName','AITC')
                $http.post('/backgroundTradeTour/getAllHavingDealTotal',paramss).then(function (res) {
                    console.log(res)
                    _this.sum = res.result.Total
                })
            },
            pageSizes(val){
                this.pageSize = val
                this.loading = true
                this.load()
            }
        }
    }
</script>
<style>
    .ivu-form-item {
        margin-bottom: 5px;
    }
</style>

